<?php
/**
 * interacion con el sky para CSS y JavaScript
 * @author rootciv
 * @version 2.0
 */
class mySkin
{
	const MEDIA_SCREEN = 'screen';
	private static $mix = array("contentCss"=>'',
	                            "contentJs" => '',
	                            "urlCss" => array(),
	                            "urlJs" => array(),
								'beforeBody' =>'',
	                            'afterBody' => '',
								'inHeaderTag' => '');
	private static $loaded = array();
	/**
	 * @var mySkinBlock
	 */
	public static $block = null;
	public static function assetCss($url, $is_external = false,$media = 'screen')
	{
		self::$mix['urlCss'][] = array(
			"src" => $is_external? $url : BASE_URL.$url,
			"media" => $media);
	}
	public static function assetJs($url, $is_external = false)
	{
			self::$mix['urlJs'][] = $is_external? $url : BASE_URL.$url;
	}
	public static function addCss($string)
	{
		self::$mix['contentCss'] .= $string;
	}
	public static function addJs($string)
	{
		self::$mix['contentJs'] .= $string;
	}
	public static function addBeforeBody($string)
	{
		self::$mix['beforeBody'] .= $string;
	}
	public static function addAfterBody($string)
	{
		self::$mix['afterBody'] .= $string;
	}
	public static function addInHeaderTag($string)
	{
		self::$mix['inHeaderTag'] .= $string;
	}
	static public function showCss()
	{
		foreach (self::$mix['urlCss'] as $url)
		{
			echo '<link rel="stylesheet" href="'.$url["src"].'" type="text/css" '.
			(empty($url['media'])?'':'media="'.$url['media'].'"' ) .' />'."\n";
		}
		self::$mix['urlCss'] = array();
		if(!empty(self::$mix["contentCss"]))
		{
			echo '<style type="text/css">'."\n".
			self::$mix['contentCss'].
			'</style>'."\n";
			self::$mix["contentCss"] = '';
		}
	}

	static public function showJs()
	{
		foreach (self::$mix["urlJs"] as $src)
		{
			echo '<script type="text/javascript" src="'. $src .'"></script>'."\n";
		}
		self::$mix['urlJs'] = array();
		if(!empty(self::$mix["contentJs"]))
		{
			echo '<script type="text/javascript">'.self::$mix["contentJs"].'</script>'."\n";
			self::$mix["contentJs"] = '';
		}
		return false;
	}
	static public function showBeforeBody()
	{
		echo self::$mix['beforeBody'];
		self::$mix['beforeBody'] = '';
	}
	static public function showAfterBody()
	{
		echo self::$mix['afterBody'];
		self::$mix['afterBody'] = '';
	}
	static public function showInHeaderTag()
	{
		echo self::$mix['inHeaderTag'];
		self::$mix['inHeaderTag'] = '';
	}
}